package xx.book.spider.util;

import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;
import xx.book.spider.entity.Book;
import xx.book.spider.service.BookService;

import javax.annotation.Resource;
import java.util.List;

@Component
public class HandlepipeLine implements Pipeline {

    @Resource
    BookService bookService;

    @Override
    public void process(ResultItems resultItems, Task task) {
        List<Book> bookList = resultItems.get("bookInfoList");
        if (bookList != null) {
            bookService.saveBatch(bookList);
        }
    }
}
